package com.example.common;

import org.apache.commons.lang3.builder.ToStringBuilder;

import java.io.Serializable;

/**
 * 状态码的返回值
 */
public class ResultWithCode implements Serializable {

    private static final long serialVersionUID = 8449563536549567992L;

    private int code;
    private String message;
    private Object data;

    public ResultWithCode() {
    }

    public ResultWithCode(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public ResultWithCode(int code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static ResultWithCode returnSuccess() {
        ResultWithCode resultWithCode = new ResultWithCode(0, "SUCCESS");
        return resultWithCode;
    }

    public static ResultWithCode returnSuccess(Object data) {
        ResultWithCode resultWithCode = new ResultWithCode(0, "SUCCESS");
        resultWithCode.setData(data);
        return resultWithCode;
    }

    public static ResultWithCode returnFailed(int code, String message) {
        ResultWithCode resultWithCode = new ResultWithCode(code, message);
        return resultWithCode;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this);
    }
}
